package com.ruoyi.water.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.water.service.IMeterLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/water/Log")
public class LogController {

    @Autowired
    private IMeterLogService MeterLogService;

    /**
     * 接收盛帆平台发送的水表数据（十六进制字符串）
     * @param hexData 盛帆平台发送的十六进制数据
     * @return 接收结果
     */
    @PostMapping("/receive")
    public AjaxResult receiveData(@RequestBody String hexData) {
        try {
            boolean result = MeterLogService.receiveAndSave(hexData);
            return result ? AjaxResult.success("数据接收成功") : AjaxResult.error("数据解析失败1");
        } catch (Exception e) {
            return AjaxResult.error("服务器异常：" + e.getMessage());
        }
    }

}
